package com.qiaoba.common.database.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.qiaoba.common.base.context.UserInfoContext;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 自动填充基础信息
 *
 * @author ailanyin
 * @date 2023-09-10 19:45:13
 */
@Component
public class BaseInfoHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createUser", UserInfoContext.getUsername(), metaObject);
        this.setFieldValByName("createTime", new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateUser", UserInfoContext.getUsername(), metaObject);
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }

}
